Total Complexity | 2 |
Total Lines | 24 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { |
||
17 | |||
18 | @Controller('projects') |
||
19 | @ApiTags('Project') |
||
20 | @ApiBearerAuth() |
||
21 | @UseGuards(AuthGuard('bearer'), RolesGuard) |
||
22 | export class CreateProjectAction { |
||
23 | constructor( |
||
24 | @Inject('ICommandBus') |
||
25 | private readonly commandBus: ICommandBus |
||
26 | ) {} |
||
27 | |||
28 | @Post() |
||
29 | @Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE) |
||
30 | @ApiOperation({summary: 'Create new project'}) |
||
31 | public async index(@Body() projectDto: ProjectDTO) { |
||
32 | try { |
||
33 | const { name, customerId, dayDuration, invoiceUnit } = projectDto; |
||
34 | const id = await this.commandBus.execute( |
||
35 | new CreateProjectCommand(name, dayDuration, invoiceUnit, customerId) |
||
36 | ); |
||
37 | |||
38 | return {id}; |
||
39 | } catch (e) { |
||
40 | throw new BadRequestException(e.message); |
||
41 | } |
||
44 |